package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LoginDemo {
    public static void main(String[] args) {
        User user =InputUtil.getInputObject(new User(),"欢迎登录","登录");
        try (
                Connection connection = DBUtil.getConnection();
                ){
            Statement state = connection.createStatement();
            String sql="SELECT id,username,password,nickname,age "+
                    "FROM userinfo "+
                    "WHERE username ='"+user.getUsername()+"' "+
                    "AND password ='"+user.getPassword()+"' ";
            ResultSet res = state.executeQuery(sql);
            System.out.println(sql);
            if (res.next()){
                System.out.println("登录成功");
            }else{
                System.out.println("登录失败,用户名或者密码不正确");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
